package vistas;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JInternalFrame;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.rmi.RemoteException;

import javax.swing.JLabel;
import javax.swing.JButton;

import controlador.Controlador;

public class AgregarUnPedido extends JInternalFrame {

	private Controlador controlador;
	private JPanel jContentPane = null;
	private JTextField nombre = null;
	private JTextField marca = null;
	private JTextField precio = null;
	private JTextField cantidad = null;
	private JTextField nroMesa = null;
	private JLabel marcalbl = null;
	private JLabel nombrelbl = null;
	private JLabel preciolbl = null;
	private JLabel cantlbl = null;
	private JLabel nroMesalbl = null;
	private JButton agregarPedido = null;
	private JButton salir = null;

	/**
	 * This is the xxx default constructor
	 */
	public AgregarUnPedido() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(344, 362);
		this.setTitle("Agregar un Pedido");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			nroMesalbl = new JLabel();
			nroMesalbl.setBounds(new Rectangle(60, 210, 100, 30));
			nroMesalbl.setText("Nro de mesa:");
			cantlbl = new JLabel();
			cantlbl.setBounds(new Rectangle(60, 140, 70, 30));
			cantlbl.setText("Cantidad");
			preciolbl = new JLabel();
			preciolbl.setBounds(new Rectangle(60, 100, 70, 30));
			preciolbl.setText("Precio");
			nombrelbl = new JLabel();
			nombrelbl.setBounds(new Rectangle(60, 60, 70, 30));
			nombrelbl.setText("Nombre");
			marcalbl = new JLabel();
			marcalbl.setBounds(new Rectangle(60, 20, 70, 30));
			marcalbl.setText("Marca");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getNombre(), null);
			jContentPane.add(getMarca(), null);
			jContentPane.add(getPrecio(), null);
			jContentPane.add(getCantidad(), null);
			jContentPane.add(getNroMesa(), null);
			jContentPane.add(marcalbl, null);
			jContentPane.add(nombrelbl, null);
			jContentPane.add(preciolbl, null);
			jContentPane.add(cantlbl, null);
			jContentPane.add(nroMesalbl, null);
			jContentPane.add(getAgregarPedido(), null);
			jContentPane.add(getSalir(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes nombre	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getNombre() {
		if (nombre == null) {
			nombre = new JTextField();
			nombre.setBounds(new Rectangle(170, 20, 100, 30));
		}
		return nombre;
	}

	/**
	 * This method initializes marca	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getMarca() {
		if (marca == null) {
			marca = new JTextField();
			marca.setBounds(new Rectangle(170, 60, 100, 30));
		}
		return marca;
	}

	/**
	 * This method initializes precio	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getPrecio() {
		if (precio == null) {
			precio = new JTextField();
			precio.setBounds(new Rectangle(170, 100, 100, 30));
		}
		return precio;
	}

	/**
	 * This method initializes cantidad	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getCantidad() {
		if (cantidad == null) {
			cantidad = new JTextField();
			cantidad.setBounds(new Rectangle(170, 140, 100, 30));
		}
		return cantidad;
	}

	/**
	 * This method initializes nroMesa	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getNroMesa() {
		if (nroMesa == null) {
			nroMesa = new JTextField();
			nroMesa.setBounds(new Rectangle(170, 210, 100, 30));
		}
		return nroMesa;
	}

	/**
	 * This method initializes agregarPedido	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getAgregarPedido() {
		if (agregarPedido == null) {
			agregarPedido = new JButton();
			agregarPedido.setBounds(new Rectangle(30, 260, 120, 40));
			agregarPedido.setText("Agregar");
			agregarPedido.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String nom =  getNombre().toString();
					String mar =  getMarca().toString();
					String pre =  getPrecio().toString();
					String cant =  getCantidad().toString();
					Integer c = Integer.parseInt(cant);
					String nroMesa =  getNroMesa().toString();
					Integer n = Integer.parseInt(nroMesa);
					try {
						controlador.agregarPedido(nom,mar,pre,c,n);
					} catch (RemoteException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}}
					
			});
	}
		return agregarPedido;}

	/**
	 * This method initializes salir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSalir() {
		if (salir == null) {
			salir = new JButton();
			salir.setBounds(new Rectangle(180, 260, 120, 40));
			salir.setText("Cancelar");
			salir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return salir;
	}

	public void setControlador(Controlador controlador) {
		this.controlador = controlador;
	}
	
 } //  @jve:decl-index=0:visual-constraint="10,10"
